//
//  CZQCycleSectionHeadView.m
//  coachmanage
//
//  Created by 众拳科技 on 2018/3/26.
//  Copyright © 2018年 众拳科技. All rights reserved.
//

#import "CZQCycleSectionHeadView.h"

@implementation CZQCycleSectionHeadView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = CSWhiteColor;
        
        /**
         分割线
         */
        UIView *sepView = [UIView new];
        sepView.backgroundColor = BackGroundColor;
        [self addSubview:sepView];
        self.sepView = sepView;
        
        /**
         点赞人数
         */
        UILabel *goodCiunLable = [UILabel new];
        goodCiunLable.font = MidBigFont;
        goodCiunLable.text = @"已有0人点赞";
        goodCiunLable.textColor = GrakColor;
        [self addSubview:goodCiunLable];
        self.goodCiunLable = goodCiunLable;
        
        UIView *scrollView = [UIView new];
        [self addSubview:scrollView];
        self.scrollView = scrollView;
        
        
        /**
         评论所有人可见，悄悄话进对方和你可见
         */
        UIButton *tipBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [tipBtn setTitle:@"🔐评论所有人可见，悄悄话进对方和你可见"];
        tipBtn.backgroundColor = ButtonBackGroundColor;
        [tipBtn setTitleColor:GrakColor];
        tipBtn.titleLabel.font = MidFont;
        [self addSubview:tipBtn];
        self.tipBtn = tipBtn;
        
        /**
         评论人数
         */
        UILabel *commentCountLable = [UILabel new];
        commentCountLable.font = MidFont;
        commentCountLable.text = @"共0条评论";
        commentCountLable.textColor = BlackColor;
        [self addSubview:commentCountLable];
        self.commentCountLable = commentCountLable;
        
        /**
         按热度
         */
//        UIButton *hotFitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//
//        [hotFitBtn setTitle:@"按热度"];
//        [hotFitBtn setImage:@"icon_browse"];
//        [hotFitBtn setTitleColor:GrakColor];
//        hotFitBtn.titleLabel.font = SmallFont;
//        [self addSubview:hotFitBtn];
//        self.hotFitBtn = hotFitBtn;
        
        [self setConstraints];
    }
    return self;
}

-(void)setConstraints
{
    
    /**
     分割线
     */
    [self.sepView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.width.left.mas_equalTo(self);
        make.height.mas_equalTo(10);
        
    }];
    
    /**
     点赞人数
     */
    [self.goodCiunLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.sepView.mas_bottom).offset(20);
        make.left.mas_equalTo(self).offset(15);
        make.height.mas_equalTo(20);
        
    }];
    
    /**
     点赞人数
     */
    [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self).offset(10);
        make.left.mas_equalTo(self.goodCiunLable.mas_right).offset(10);
        make.right.mas_equalTo(self).offset(-15);
        make.bottom.mas_equalTo(self.tipBtn.mas_top);
    }];

    
    
    /**
     评论所有人可见，悄悄话进对方和你可见
     */
    [self.tipBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.width.left.mas_equalTo(self);
        make.top.mas_equalTo(self.goodCiunLable.mas_bottom).offset(10);
        make.height.mas_equalTo(40);
        
    }];
    
    /**
     评论人数
     */
    [self.commentCountLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self).offset(15);
        make.top.mas_equalTo(self.tipBtn.mas_bottom).offset(15);
        make.bottom.mas_equalTo(self).offset(-10);
        
    }];
    
//    /**
//     按热度
//     */
//    [self.hotFitBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
//        
//        make.centerY.mas_equalTo(self.commentCountLable);
//        make.right.mas_equalTo(self).offset(-15);
//        
//    }];
//    
//    [self.hotFitBtn imageOnTheTitleLeftWithSpace:10];
    
}

-(void)setGoodArrM:(NSMutableArray *)goodArrM
{
    _goodArrM = goodArrM;

    UIImageView *imgView;

    NSLog(@"%@",goodArrM);

    for (int i = 0; i < goodArrM.count; i ++) {

        UIImageView *img = [UIImageView new];

        img.userInteractionEnabled = YES;

        


        if ([goodArrM[i][@"Pic"] isKindOfClass:[NSNull class]]) {
            img.image = PlaceHold;
        }else
        {
            [img sd_setImageWithURL:[NSURL URLWithString:[Helper imageUrlStringToChinese:[goodArrM[i] valueForKey:@"Pic"] imageType:nil]] placeholderImage:PlaceHold];
        }


        [self.scrollView addSubview:img];

        img.tag = 300 + i;





        if (i == 0) {

            [img mas_remakeConstraints:^(MASConstraintMaker *make) {

                make.top.mas_equalTo(self.scrollView).offset(5);
                make.bottom.mas_equalTo(self.scrollView).offset(-5);
                make.right.mas_equalTo(self.scrollView);
                make.width.mas_equalTo(img.mas_height);


            }];

        }else if (i == goodArrM.count - 1){

            [img mas_remakeConstraints:^(MASConstraintMaker *make) {

                make.top.bottom.mas_equalTo(imgView);
                make.right.mas_equalTo(imgView.mas_left).offset(0);

                make.width.height.mas_equalTo(imgView);

            }];

        }else
        {
            [img mas_remakeConstraints:^(MASConstraintMaker *make) {

                make.top.bottom.mas_equalTo(imgView);
                make.right.mas_equalTo(imgView.mas_left).offset(0);
                //                    make.right.mas_equalTo
                make.width.height.mas_equalTo(imgView);

            }];

        }
        imgView = img;

        
        img.layer.cornerRadius = 20;
        
        img.clipsToBounds = YES;

    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
